package com.bjypc.youth.web.json;

import org.apache.log4j.Logger;

import com.bjypc.youth.entity.AdultPerson;
import com.bjypc.youth.entity.FutureJudgment;
import com.bjypc.youth.entity.ImportentLevel;
import com.bjypc.youth.entity.InterpersonalRelationship;
import com.bjypc.youth.entity.LifeStyle;
import com.bjypc.youth.entity.PersonAssociation;
import com.bjypc.youth.entity.PersonConsume;
import com.bjypc.youth.entity.PersonalFeeling;
import com.bjypc.youth.entity.PersonalInterest;
import com.bjypc.youth.entity.TimeUsing;
import com.bjypc.youth.service.IAdultPersonService;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class AdultTestAction extends ActionSupport {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 8705273808015920398L;
	/**
	 * Entities that will be persisted
	 */
	private AdultPerson person;
	private LifeStyle lifeStyle;
	private InterpersonalRelationship relationship;
	private PersonAssociation personAssociation;
	private TimeUsing timeUsing;
	private PersonalFeeling personalFeeling;
	private PersonalInterest interest;
	private ImportentLevel importentLevel;
	private FutureJudgment futureJudgment;
	private PersonConsume personConsume;
	private IAdultPersonService adultPersonService;

	/**
	 * status field to indicate whether operation succeeds
	 */
	private boolean success;
	private boolean failure;

	public String execute() {
		if (null != person && person.getId() == null) {
			if (null != lifeStyle) {
				person.setLifeStyle(lifeStyle);
			}
			// add InterpersonalRelationship
			if (null != relationship) {
				person.setInterpersonalRelationship(relationship);
			}
			if(null!=personAssociation){
				person.setPersonAssociation(personAssociation);
			}
			// add PersonalInterest
			if (null != interest) {
				person.setPersonalInterest(interest);
			}
			// add TimeUsing
			if (null != timeUsing) {
				person.setTimeUsing(timeUsing);
			}
			if (null != personalFeeling) {
				person.setPersonalFeeling(personalFeeling);
			}
			if (null != this.importentLevel) {
				person.setImportentLevel(importentLevel);
			}
			if (null != this.futureJudgment) {
				person.setFutureJudgment(futureJudgment);
			}
			if (null != this.personConsume) {
				person.setPersonConsume(personConsume);
			}
			this.adultPersonService.save(person);
			logger.info("Person with sex " + person.getSex()
					+ " has been persisted,id is " + this.person.getId());
			this.success = true;
			this.failure = false;
		} else {
			if (null == person)
				logger.debug("Person is null,can't be saved to DB");
			else if (null != person.getId())
				logger.debug("Person with existed id(" + person.getId()
						+ ") can't be saved to DB");

		}
		return Action.SUCCESS;
	}

	@JSON(serialize = false)
	public AdultPerson getPerson() {
		return person;
	}

	public void setPerson(AdultPerson person) {
		this.person = person;
	}

	protected Logger logger = Logger.getLogger(AdultTestAction.class);

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public boolean isFailure() {
		return failure;
	}

	public void setFailure(boolean failure) {
		this.failure = failure;
	}

	@JSON(serialize = false)
	public LifeStyle getLifeStyle() {
		return lifeStyle;
	}

	public void setLifeStyle(LifeStyle lifeStyle) {
		this.lifeStyle = lifeStyle;
	}

	@JSON(serialize = false)
	public InterpersonalRelationship getRelationship() {
		return relationship;
	}

	public void setRelationship(InterpersonalRelationship relationship) {
		this.relationship = relationship;
	}

	@JSON(serialize = false)
	public PersonalInterest getInterest() {
		return interest;
	}

	public void setInterest(PersonalInterest interest) {
		this.interest = interest;
	}

	@JSON(serialize = false)
	public TimeUsing getTimeUsing() {
		return timeUsing;
	}

	public void setTimeUsing(TimeUsing timeUsing) {
		this.timeUsing = timeUsing;
	}

	@JSON(serialize = false)
	public PersonalFeeling getPersonalFeeling() {
		return personalFeeling;
	}

	public void setPersonalFeeling(PersonalFeeling personalFeeling) {
		this.personalFeeling = personalFeeling;
	}

	@JSON(serialize = false)
	public ImportentLevel getImportentLevel() {
		return importentLevel;
	}

	public void setImportentLevel(ImportentLevel importentLevel) {
		this.importentLevel = importentLevel;
	}

	@JSON(serialize = false)
	public FutureJudgment getFutureJudgment() {
		return futureJudgment;
	}

	public void setFutureJudgment(FutureJudgment futureJudgment) {
		this.futureJudgment = futureJudgment;
	}

	@JSON(serialize = false)
	public PersonConsume getPersonConsume() {
		return personConsume;
	}

	public void setPersonConsume(PersonConsume personConsume) {
		this.personConsume = personConsume;
	}

	@JSON(serialize = false)
	public IAdultPersonService getAdultPersonService() {
		return adultPersonService;
	}

	public void setAdultPersonService(IAdultPersonService adultPersonService) {
		this.adultPersonService = adultPersonService;
	}

	@JSON(serialize = false)
	public PersonAssociation getPersonAssociation() {
		return personAssociation;
	}

	public void setPersonAssociation(PersonAssociation personAssociation) {
		this.personAssociation = personAssociation;
	}

}
